<%@page import="entities.Category"%>
<%@page import="java.util.List"%>
<%@page import="entities.AutoSite"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>

<%
TreeMap check = (TreeMap) request.getAttribute("check");
String success = (String) request.getAttribute("success");
AutoSite autoSite = (AutoSite) request.getAttribute("autoSite");
String form = (String) request.getAttribute("form");
List<Category> categories = (List<Category>) request.getAttribute("categories");
%>

<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>

<script type="text/javascript" src="/admin/js/form_site.js"></script>
		
		<div class="maincontent noright">
        	<div class="maincontentinner">
                <ul class="maintabmenu multipletabmenu">
                	<li><a href="/admin/site/list">List Sites</a></li>
                	<li class="current"><a href="/admin/site/add">Auto Sites</a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">
					<% if (success != null) {%>
					<div class="notification msgsuccess">
                        <a class="close"></a>
                        <p><%=success %></p>
                    </div>
					<% } %>
                    <div class="contenttitle">
                    	<h2 class="form"><span><%=form.equalsIgnoreCase("add") ? "Add Site" : "Edit Site" %></span></h2>
                    </div><!--contenttitle-->
            
                    <form method="post" action="#" class="stdform" id="edit_site_form">
                    	
                        <p>
                        	<label>Sitemaps</label>
                            <span class="field">
                            	<input type="text" class="mediuminput" name="url" id="s_url" value="<%=autoSite.getUrl() != null ? autoSite.getUrl() : "" %>" 
                            		<%=form.equalsIgnoreCase("add") ? "" : "readonly=\"readonly\"" %>>
                            	<% if (check.get("url") != null) { %>
									<label for="s_url" generated="true" class="error"><%=check.get("url") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Get Page</label>
                            <span class="field formwrapper">
                            		Yes <input class="input type" type="radio" value="true" style="width: auto;" name="getPage" <%=autoSite.isGetPage() == true ? "checked=\"checked\"" : "" %>> &nbsp;&nbsp;&nbsp;&nbsp; 
                            		No  <input class="input type" type="radio" value="false" style="width: auto;" name="getPage" <%=autoSite.isGetPage() == false ? "checked=\"checked\"" : "" %>>
								<% if (check.get("getPage") != null) { %>
									<label for="s_getPage" generated="true" class="error"><%=check.get("getPage") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Selector of Title Link</label>
                            <span class="field">
                            	<input type="text" class="mediuminput" name="regLink" id="s_regLink" value="<%=autoSite.getRegLink() != null ? autoSite.getRegLink() : "" %>">
                            	<% if (check.get("regLink") != null) { %>
									<label for="s_regLink" generated="true" class="error"><%=check.get("regLink") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Time Schedule</label>
                            <span class="field">
                            	<select name="scheduleSite" id="schedule-site">
									<option value="60" <%=autoSite.getScheduleSite() == 60 ? "selected=\"selected\"" : "" %>>1 hour</option>
									<option value="120" <%=autoSite.getScheduleSite() == 120 ? "selected=\"selected\"" : "" %>>2 hour</option>
									<option value="180" <%=autoSite.getScheduleSite() == 180 ? "selected=\"selected\"" : "" %>>3 hour</option>
									<option value="360" <%=autoSite.getScheduleSite() == 360 ? "selected=\"selected\"" : "" %>>6 hour</option>
									<option value="720" <%=autoSite.getScheduleSite() == 720 ? "selected=\"selected\"" : "" %>>12 hour</option>
									<option value="1080" <%=autoSite.getScheduleSite() == 1080 ? "selected=\"selected\"" : "" %>>18 hour</option>
									<option value="1440" <%=autoSite.getScheduleSite() == 1440 ? "selected=\"selected\"" : "" %>>24 hour</option>
								</select>
                            	<% if (check.get("scheduleSite") != null) { %>
									<label for="s_scheduleSite" generated="true" class="error"><%=check.get("scheduleSite") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Category</label>
                            <span class="field">
                            	<select name="category" id="s_category">
                            		<% for (int i = 0; i < categories.size(); i++) { %>
                            		<option value="<%=categories.get(i).getId() %>" <%=autoSite.getCategory().equalsIgnoreCase(categories.get(i).getId()) ? "selected=\"selected\"" : "" %>><%=categories.get(i).getName() %></option>
                            		<% } %>
                            	</select>
                            	<% if (check.get("category") != null) { %>
									<label for="s_category" generated="true" class="error"><%=check.get("category") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p class="page">
                        	<label>Time schedule Page</label>
                            <span class="field">
                            	<select name="scheduleSitePage" id="schedule-site-page">
									<option value="60" <%=autoSite.getScheduleSitePage() == 60 ? "selected=\"selected\"" : "" %>>1 hour</option>
									<option value="120" <%=autoSite.getScheduleSitePage() == 120 ? "selected=\"selected\"" : "" %>>2 hour</option>
									<option value="180" <%=autoSite.getScheduleSitePage() == 180 ? "selected=\"selected\"" : "" %>>3 hour</option>
									<option value="360" <%=autoSite.getScheduleSitePage() == 360 ? "selected=\"selected\"" : "" %>>6 hour</option>
									<option value="720" <%=autoSite.getScheduleSitePage() == 720 ? "selected=\"selected\"" : "" %>>12 hour</option>
									<option value="1080" <%=autoSite.getScheduleSitePage() == 1080 ? "selected=\"selected\"" : "" %>>18 hour</option>
									<option value="1440" <%=autoSite.getScheduleSitePage() == 1440 ? "selected=\"selected\"" : "" %>>24 hour</option>
								</select>
                            	<% if (check.get("scheduleSitePage") != null) { %>
									<label for="s_scheduleSitePage" generated="true" class="error"><%=check.get("scheduleSitePage") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p class="page">
                        	<label>Site pages</label>
                            <span class="field">
                            	<input type="text" class="mediuminput" name="sitePage" id="s_sitePage" value="<%=autoSite.getSitePage() != null ? autoSite.getSitePage() : "" %>">
                            	<% if (check.get("sitePage") != null) { %>
									<label for="s_sitePage" generated="true" class="error"><%=check.get("sitePage") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p class="page">
                        	<label>Current Page</label>
                            <span class="field">
                            	<input type="text" class="mediuminput" name="currentPage" id="s_currentPage" value="<%=autoSite.getCurrentPage() %>">
                            	<% if (check.get("currentPage") != null) { %>
									<label for="s_currentPage" generated="true" class="error"><%=check.get("currentPage") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p class="page">
                        	<label>Total Page</label>
                            <span class="field">
                            	<input type="text" class="mediuminput" name="totalPage" id="s_totalPage" value="<%=autoSite.getTotalPage() %>">
                            	<% if (check.get("totalPage") != null) { %>
									<label for="s_totalPage" generated="true" class="error"><%=check.get("totalPage") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label></label>
                            <span class="field">
                            	<a href="#popchecksite" class="popchecksite">Check info</a>
                            </span>
                        </p>
                        
                        <p class="stdformbutton">
                        	<button class="submit radius2">Submit</button>
                            <input type="reset" value="Reset" class="reset radius2">
                        </p>
                        
                    </form>
                    
                    <br clear="all">
                    
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp">
            	<jsp:param name="language" value="1" />
			</jsp:include>
            
        </div>
        <div style="display: none">
			<div id="popchecksite">
				<div style="text-align: center; padding-top: 200px;">
					<h2>Loadding....</h2>
				</div>
			</div>
		</div>
<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>